
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何判断一个链表中是否存在环？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何判断一个链表中是否存在环？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">算法</div>
          <div class="card-question">“快慢指针”算法（弗洛伊德循环检测算法）的基本思路是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">算法</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">定义一个快指针(fast)和一个慢指针(slow)，都从头节点开始。慢指针每次移动一个节点，快指针每次移动两个节点。如果链表中存在环，快指针最终会追上慢指针。</div>
          </div>
          <div class="card-source">来源: 1. 快慢指针（弗洛伊德循环检测算法）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在使用快慢指针算法时，如何确定链表中不存在环？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在循环移动指针的过程中，如果快指针(fast)变为 null 或者快指针的下一个节点(fast.next)为 null，则说明快指针到达了链表的尾部，链表没有环。</div>
          </div>
          <div class="card-source">来源: 1. 快慢指针（弗洛伊德循环检测算法）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">算法</div>
          <div class="card-question">使用哈希表方法检测链表环的核心逻辑是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">算法</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">遍历链表，将每个节点的引用存储在哈希表中。在遍历时，如果发现当前节点已经存在于哈希表中，就说明链表存在环。</div>
          </div>
          <div class="card-source">来源: 2. 哈希表方法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">优缺点</div>
          <div class="card-question">与快慢指针算法相比，哈希表方法在检测链表环时有什么主要缺点？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">优缺点</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">哈希表方法需要额外的空间来存储哈希表，其空间复杂度为O(n)。</div>
          </div>
          <div class="card-source">来源: 2. 哈希表方法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">算法</div>
          <div class="card-question">“修改节点值”方法是如何检测链表环的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">算法</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">遍历链表时，将访问过的每个节点的值都修改为一个特殊的标记。如果在遍历过程中遇到一个节点的值已经是该特殊标记，则说明链表存在环。</div>
          </div>
          <div class="card-source">来源: 3. 修改节点值方法</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">优缺点</div>
          <div class="card-question">“修改节点值”方法来检测链表环存在什么重大缺陷？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">优缺点</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">这种方法会修改链表节点原来的值，这可能会影响到链表的其他相关操作或业务逻辑。</div>
          </div>
          <div class="card-source">来源: 3. 修改节点值方法</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
